package org.kust.bbs.shenhe.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.kust.bbs.common.web.JsonPage;
import org.kust.bbs.common.web.JsonResult;
import org.kust.bbs.shenhe.entity.shenheInvVO;
import org.kust.bbs.shenhe.entity.shenheQueAnsVO;
import org.kust.bbs.shenhe.mapper.shenheMapper;
import org.kust.bbs.shenhe.service.shenInvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/shenhe")
@Api(tags = "审核控制模块")
public class shenInvController {

    @Autowired
    shenheMapper mapper;

    @Autowired
    shenInvService service;

    @GetMapping("/getInv")
    @ApiOperation("获取所有未审核帖子")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "page", dataType = "int",
                    required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "int",
                    required = true)
    })
    public JsonResult<JsonPage<shenheInvVO>> getAllInv(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize

    ) {
        PageInfo<shenheInvVO> pageInfo = service.getAllInvOrdersByPage(page, pageSize);
        JsonPage<shenheInvVO> jsonPage = JsonPage.restPage(pageInfo);
        return JsonResult.ok(jsonPage);
    }

    @GetMapping("/getQueAns")
    @ApiOperation("获取所有未审核问题")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "page", dataType = "int",
                    required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "int",
                    required = true)
    })
    public JsonResult<JsonPage<shenheQueAnsVO>> getAllQueAns(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize

    ) {
        PageInfo<shenheQueAnsVO> pageInfo = service.getAllQueAnsOrdersByPage(page, pageSize);
        JsonPage<shenheQueAnsVO> jsonPage = JsonPage.restPage(pageInfo);
        return JsonResult.ok(jsonPage);
    }

    @GetMapping("/shenInv")
    @ApiOperation("审核帖子")

    public JsonResult<Void> updateInvSta(Long id) {
        service.updateInvState(id);
        return JsonResult.ok();
    }

    @GetMapping("/shenQueAns")
    @ApiOperation("审核问题")
    public JsonResult<Void> updateQueAnsSta(Long id) {
        service.updateQueAnsState(id);
        return JsonResult.ok();
    }


}
